﻿using GeneralClasses;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace TestGeneralClasses
{


    /// <summary>
    ///This is a test class for ScheduleTest and is intended
    ///to contain all ScheduleTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ScheduleTest
    {

        #region VARIABLES
        private TestContext testContextInstance;

        #endregion


        #region PROPERTIES

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #endregion

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for setWithIndexes
        ///</summary>
        [TestMethod()]
        public void setWithIndexesTest()
        {
            //Schedule schedule = new Schedule();
            Schedule schedule = Schedule.getWeeklyTemplateSchedule();


            #region unused
            //try saving the template
            // schedule.saveData();
            // schedule.writeOutObjectTree(0, 0);
            // return;
            /*
            //test day DateTimes
            UTIL.sayDebug("testing day datetimes");
            for (int i = 0; i < schedule.Days.Count; i++)
            {
                UTIL.sayDebug("i: " + i + "_ " + schedule.Days[i].DateTime.ToString());
            }
            */

            /*
            //test shift daytimes
            UTIL.sayDebug("testing shift datetimes");
            for (int i = 0; i < schedule.Days[0].Departments[0].Shifts.Count; i++)
            {
                Shift shift = schedule.Days[0].Departments[0].Shifts[i];
                UTIL.sayDebug("count: (" + i + ") _ " + shift.StartTime + " , " + shift.EndTime);
            }
             * */

            /*  //test unique shifts
              UTIL.sayDebug("testing unique shifts");
              schedule.Days[0].Departments[0].shiftsOnThisDay(schedule.Days[0].DateTime)[0].Persons.Add(Person.loadAllActiveNurses()[0]);
              schedule.Days[1].Departments[0].shiftsOnThisDay(schedule.Days[1].DateTime)[0].Persons.Add(Person.loadAllActiveNurses()[1]);
              schedule.DepartmentMasterList[0].writeOutObjectTree(0, 0, 0, schedule.Days[0].DateTime);
              schedule.DepartmentMasterList[0].writeOutObjectTree(0, 0, 0, schedule.Days[1].DateTime);
              UTIL.sayDebug(schedule.Days[0].Departments[0].shiftsOnThisDay(schedule.Days[0].DateTime)[0].Persons[0].PERID.ToString());
              UTIL.sayDebug(schedule.Days[1].Departments[0].shiftsOnThisDay(schedule.Days[1].DateTime)[0].Persons[0].PERID.ToString());
              */
            #endregion


            List<int> personIndexes = new List<int>();


            int numberOfDepartments = schedule.DepartmentMasterList.Count;
            int peoplePerDepartment = 3;
            int numberOfShifts = 3;
            int numberOfDays = 7;
            int numberOfActiveNurses = Person.loadAllActiveNurses().Count;

            int peoplePerShift = peoplePerDepartment * numberOfDepartments;
            int peoplePerDay = numberOfShifts * peoplePerShift;
            int numberOfPeopleIndexes = peoplePerDay * numberOfDays;


            //add the number of people to the list for each day
            Random random = new Random();
            for (int i = 0; i < numberOfPeopleIndexes; i++)
            {
                personIndexes.Add(random.Next(numberOfActiveNurses));
                while ((i >= 2) && ((personIndexes[i] == personIndexes[i - 1]) || (personIndexes[i] == personIndexes[i - 2])))
                {
                    personIndexes[i] = random.Next(numberOfActiveNurses);
                }
            }

            //add N people to the masterperson list
            schedule.PersonMasterList = Person.loadAllActiveNurses();
            //for (int i = 0; i < numberOfActiveNurses; i++) { schedule.PersonMasterList.Add(new Person()); }

            schedule.setWithIndexes(personIndexes, numberOfDepartments, peoplePerDepartment, numberOfShifts, peoplePerShift, peoplePerDay, numberOfDays);



            schedule.saveAsText();

            DateTime start = DateTime.Today;
            DateTime end = DateTime.Today;
            end = end.AddDays(7);

            String text = Schedule.loadText(start, end);
            UTIL.sayDebug(text);
        }
    }
}
